home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / conf / sf.proto < prev    next >
Encoding:
Text File  |  1991-09-16  |  2.2 KB  |  72 lines

  1. #! /bin/sh
  2. # spacefor - determine available disk space
  3. # About how many things of $1 bytes will fit in the available space for
  4. # stuff of type $2 ("incoming", "articles", "control", "outbound $3",
  5. # or "archive") without cramping things too badly?
  6. #
  7. # You'll have to change this -- your blocksize, minimum-free-desired amounts,
  8. # and df output format will probably differ, and you may need to name
  9. # your filesystems explicitly.  Note that all amounts are expressed in
  10. # target-filesystem blocks, not some arbitrary absolute unit.  (Absolute
  11. # units might be better but there is no agreement on what they should be.)
  12.  
  13. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  14. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  15.  
  16. PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH
  17. umask $NEWSUMASK
  18.  
  19. # punt to server if necessary
  20. if test -r $NEWSCTL/server
  21. then
  22.     server="`cat $NEWSCTL/server`"
  23.     me="`hostname`"
  24.     if test " $server" != " $me"
  25.     then
  26.         exec rsh $server -n /bin/sh -c "'PATH=$PATH `basename $0` $*'"
  27.         # does not return
  28.     fi
  29. fi
  30.  
  31. # head off special case
  32. case "$1" in
  33. 0)    echo 10000 ; exit 0 ;;
  34. esac
  35.  
  36. # argument to df, df units, and free space desired (in df units)
  37. dfunit=1024            # default df unit (bytes)
  38. case "$2" in
  39. incoming)    arg="$NEWSARTS/in.coming" ; desire=5000 ;;
  40. articles)    arg="$NEWSARTS" ; desire=5000 ;;
  41. control)    arg="$NEWSCTL" ; desire=3000 ;;        # for expire, mostly
  42. outbound)    arg="/usr/spool/uucp" ; desire=10000 ;;    # ignore $3
  43. archive)    arg="$NEWSARTS" ; desire=1 ;;        # system-specific
  44. *)        echo "$0: bad type argument \`$2'!!" >&2
  45.         exit 2 ;;
  46. esac
  47.  
  48. # In the following, the initialization of nf determines which field the
  49. # block count comes from, and the one for nr determines which line.  For
  50. # System V, the Makefile edits in a sed which tries to strip silliness
  51. # off in a reasonably System-V-variant-independent way.  Expr would be
  52. # faster than awk, but on a 16-bit machine, expr does 16-bit arithmetic,
  53. # which isn't enough.
  54.  
  55. # this is set up for the stupid 4BSD df
  56. df $arg | awk "BEGIN { nf = 4 ; nr = 2 }
  57.     NR == nr && NF >= nf {
  58.         nb = (\$nf - $desire) * $dfunit / $1
  59.         if (nb > 10000)
  60.             nb = 10000    # ensure representable as integer
  61.         nb = int(nb)
  62.         if (nb <= 0)
  63.             print 0
  64.         else
  65.             print nb
  66.         exit
  67.     }
  68.     NR == nr && NF < nf {        # idiotic Berkeley continuation
  69.         nr += 1
  70.         nf -= 1
  71.     }"
  72.